import { CellRenderer } from "../../../../fl/controls/listClasses/CellRenderer";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ObjCreate } from "../common/ObjCreate";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { TitleInfo } from "../../resource/info/TitleInfo";
import { ToolTipsManager } from "../../../../com/mui/manager/ToolTipsManager";
import { TitleToolTip } from "./TitleToolTip";
import { GameController } from "../../mvc/GameController";
import { ITitleModule } from "../../../../modules/interfaces/ITitleModule";
import { GButton } from "../../../../com/mui/controls/GButton";
//class TitleCellRenderer
    
    export  class TitleCellRenderer extends CellRenderer
    {
        constructor()
        {
            super();
            this.width = 180;
            this.initStyles();
            this.mouseChildren = true;
            this.doubleClickEnabled = false;
            this.mouseEnabled = true;
            this.create();
            return;
        }

        /* internal  */initStyles(): void
        {
            this.setStyle("downSkin", GlobalClass.getBitmap("Friend_over"));
            this.setStyle("overSkin", GlobalClass.getBitmap("Friend_over"));
            this.setStyle("upSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("selectedDownSkin", GlobalClass.getBitmap("Friend_over"));
            this.setStyle("selectedOverSkin", GlobalClass.getBitmap("Friend_over"));
            this.setStyle("selectedUpSkin", GlobalClass.getBitmap("Friend_over"));
            return;
        }

        /* internal  */create(): void
        {
            this._btnIcon = ObjCreate.createGButton("", 0, 2, 23, 23, this, "TitleIconBtn");
            this._btnIcon.doubleClickEnabled = true;
            this._btnIcon.drawNow();
            this._tfTitleName = ObjCreate.createTextField("", 23, 5, 125, 20, this);
            var loc1=new Object /* flash.display.Sprite */();
            loc1.graphics.beginFill(16777215, 0.01);
            loc1.graphics.drawRect(23, 0, 123, 25);
            loc1.graphics.endFill();
            loc1.doubleClickEnabled = true;
            loc1.mouseEnabled = true;
            loc1.cacheAsBitmap = true;
            this.addChild(loc1);
            loc1.addEventListener(flash.events.MouseEvent.DOUBLE_CLICK, this.ondblClick);
            this._btnIcon.addEventListener(flash.events.MouseEvent.DOUBLE_CLICK, this.ondblClick);
            return;
        }

        /* internal  */ondblClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._isShowGuildName) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.TitleEnableTitle, this._titleInfo.code));
            }
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            super.data = arg1;
            if (arg1.hasOwnProperty("titleInfo")) 
            {
                this._titleInfo = arg1["titleInfo"] as TitleInfo;
                this._isShowGuildName = arg1["isShowGuildName"];
                this.refresh();
                this.drawNow();
            }
            return;
        }

        public /* override */ set label(arg1: string)
        {
            return;
        }

        /* internal  */refresh(): void
        {
            if (!this._titleInfo) 
            {
                return;
            }
            if (this._titleInfo.iconType == TitleInfo.Text) 
            {
                this._btnIcon.visible = false;
            }
            else 
            {
                this._btnIcon.visible = true;
                this._btnIcon.toolTipData = this._titleInfo;
                ToolTipsManager.unregister(this._btnIcon);
                ToolTipsManager.register(this._btnIcon, TitleToolTip);
            }
            this._btnIcon.drawNow();
            this._tfTitleName.text = this._isShowGuildName ? (GameController.title.view as ITitleModule).getTitleName(this._titleInfo, false) : this._titleInfo.name;
            return;
        }

        /* internal */ /* var */_isShowGuildName: Boolean=false;

        /* internal */ /* var */_titleInfo: TitleInfo;

        /* internal */ /* var */_btnIcon: GButton;

        /* internal */ /* var */_tfTitleName: Object /* flash.text.TextField */;
    }
